﻿/*
   Copyright 2012 University of Southampton

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
*/

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Xml.Serialization;
using System.Data.Linq;
using System.Xml;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
using uk.ac.soton.ses.DAL;
using System.Diagnostics;
using System.Data.EntityClient;

namespace uk.ac.soton.ses
{
    public abstract class ExperimentMetadataContainer
    {
        protected ExperimentBO _experiment = null;
        protected List<ExperimentDataFileMetadataContainer> _experimentDataFiles = null;

        public ExperimentBO Experiment { get { return this._experiment; } }
        public List<ExperimentDataFileMetadataContainer> ExperimentDataFiles { get { return this._experimentDataFiles; } }

        protected ExperimentMetadataContainer()
        {
        }

        public abstract ExperimentDataFileMetadataContainer AddExperimentDataFile(ExperimentDataFileBO experimentDataFile);


        public static ExperimentMetadataContainerXML LoadFromXML(string experimentBasePath)
        {
            ExperimentMetadataContainerXML metadata = new ExperimentMetadataContainerXML(experimentBasePath);
            return metadata;
        }
        public static ExperimentMetadataContainerDB LoadFromDB(int id)
        {
            ExperimentMetadataContainerDB metadata = new ExperimentMetadataContainerDB(id);
            return metadata;
        }
        public static ExperimentMetadataContainerDB LoadFromDB(string name, string basePath)
        {
            ExperimentMetadataContainerDB metadata = new ExperimentMetadataContainerDB(name, basePath);
            return metadata;
        }
        public static ExperimentMetadataContainerFileSystem LoadFromFileSystem(HDCPath experimentPath)
        {
            ExperimentMetadataContainerFileSystem metadata = new ExperimentMetadataContainerFileSystem(experimentPath);
            return metadata;
        }
        public static ExperimentMetadataContainerFileSystem LoadFromFileSystem(HDCPath experimentPath, ExperimentMetadataContainerDB dbMeta)
        {
            ExperimentMetadataContainerFileSystem fsMeta = new ExperimentMetadataContainerFileSystem(experimentPath, dbMeta);
            return fsMeta;
        }

        public virtual void RenameExperiment(string newName, string newExperimentBasePath)
        {
            this._experiment.Name = newName;
            this._experiment.DefaultBasePath = newExperimentBasePath;
        }

        public virtual void SaveChanges()
        {
        }
    }

}
